package com.doujiao.auth.controller;

import com.doujiao.auth.service.AdminGroupPermissionService;
import com.doujiao.core.auth.dto.AdminGroupPermissionCreateDTO;
import com.doujiao.core.auth.dto.AdminGroupPermissionQueryDTO;
import com.doujiao.core.auth.entity.AdminGroupPermission;
import com.doujiao.core.auth.vo.AdminGroupPermissionPageVO;
import com.doujiao.core.Result;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 管理员组权限控制器
 *
 * @author wuyunbin
 * @since 2025-05-24
 */
@RestController
@RequestMapping("/admin/group/permission")
@RequiredArgsConstructor
@Tag(name = "管理员组权限管理")
public class AdminGroupPermissionController {

    private final AdminGroupPermissionService adminGroupPermissionService;

    @GetMapping("/page")
    @Operation(summary = "分页查询管理员组权限")
    @ApiOperationSupport(order = 1)
    public Result<AdminGroupPermissionPageVO> page(AdminGroupPermissionQueryDTO queryDTO) {
        return Result.success(adminGroupPermissionService.page(queryDTO));
    }

    @PostMapping("/batch")
    @Operation(summary = "批量创建管理员组权限")
    @ApiOperationSupport(order = 2)
    public Result<List<AdminGroupPermission>> batchCreate(@RequestBody @Validated AdminGroupPermissionCreateDTO createDTO) {
        return Result.success(adminGroupPermissionService.batchCreate(createDTO));
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "删除管理员组权限")
    @ApiOperationSupport(order = 3)
    public Result<Boolean> delete(@PathVariable @Parameter(description = "权限ID") Long id) {
        return Result.success(adminGroupPermissionService.delete(id));
    }

    @GetMapping("/list/{groupId}")
    @Operation(summary = "获取管理员组的所有权限标识")
    @ApiOperationSupport(order = 4)
    public Result<List<String>> getPermissionsByGroupId(@PathVariable @Parameter(description = "管理员组ID") Long groupId) {
        return Result.success(adminGroupPermissionService.getPermissionsByGroupId(groupId));
    }

    @DeleteMapping("/group/{groupId}")
    @Operation(summary = "删除管理员组的所有权限")
    @ApiOperationSupport(order = 5)
    public Result<Boolean> deleteByGroupId(@PathVariable @Parameter(description = "管理员组ID") Long groupId) {
        return Result.success(adminGroupPermissionService.deleteByGroupId(groupId));
    }
}
